package com.housekeeping.housekeeping.usermanagement.controller;

import com.alibaba.fastjson.JSONObject;
import com.housekeeping.housekeeping.usermanagement.entity.InformationUser;
import com.housekeeping.housekeeping.usermanagement.service.DelService;
import com.housekeeping.housekeeping.usermanagement.service.impl.DelServiceImpl;
import com.housekeeping.housekeeping.usermanagement.utils.ResponseEntity;
import com.housekeeping.housekeeping.usermanagement.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/*
* 删除
* */
@WebServlet("/user/del")
public class DelController extends HttpServlet {
    static DelService operation = new DelServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        String parameter = req.getParameter("information");
        ResponseEntity entity = null;
        try {
            //解析转换成InformationUser类型
            InformationUser information = JSONObject.parseObject(parameter, InformationUser.class);
            int i = operation.delOperation(information);

            if (i > 0) { entity = ResponseEntity.success(null);
            } else { entity = ResponseEntity.error(405, "添加失败"); }
        } catch (SQLException throwables) { throwables.printStackTrace(); }
        ResponseUtils.resp(resp, entity);
    }
}
